from tests.pytests.helpers.codegen_helpers import compile_chunk, assert_code_contains


def test_or_and_precedence():
    def f(a: bool, b: bool, c: bool) -> bool:
        return (a or b) and c

    block = compile_chunk(f)
    assert_code_contains(
        block,
        """
        bool f(bool a, bool b, bool c) {
            return (a || b) && c;
        }
        """,
    )


def test_not_or_precedence():
    def g(a: bool, b: bool) -> bool:
        return (not a) or b

    block = compile_chunk(g)
    assert_code_contains(
        block,
        """
        bool g(bool a, bool b) {
            return !a || b;
        }
        """,
    )


def test_chained_compare():
    def h(a: int, b: int, c: int) -> bool:
        return a < b == c

    block = compile_chunk(h)
    assert_code_contains(
        block,
        """
        bool h(int a, int b, int c) {
            return a < b && b == c;
        }
        """,
    )
